<?php

/**
*
*	Interface for Plugins
*
*/
class RIPlugin
{
	var $parent;
	var $childs;
	var $tplfolder;
	var $operatorid;
	
	function IPlugin($parent = null)
	{
		$this->childs = null;
		$this->parent = $parent;
		$this->tplfolder = "";
	}
	
	/*
	*	Retrieve plugin tag (tag is used in page creating)
	*
	*/
	function getPluginTag()
	{
		return "UNKNOWN";
	}
	
	/*
	*	Retrieve plugin readable name
	*
	*/
	function getPluginName()
	{
		return "Unknown Plugin";
	}
	
	/*
	*	Retrieve plugin version (Version.Release.Build)
	*
	*/
	function getPluginVersion()
	{
		return "1.0.0";
	}
	

	/*
	*	Initialize plugin before start
	*
	*/
	function initialize()
	{
		return true;
	}

	/*
	*	Shutdown plugin after work iteration
	*
	*/
	function shutdown()
	{
		return true;
	}
	

	/*
	*	Add sub-plugin to current level plugin
	*
	*/
	function AddSubPlugin(&$obj)
	{
		if(!is_a($obj, "IPlugin"))
		{
			return false;
		}
		$tag = $obj->getPluginTag();
		if(isset($this->childs[$tag]))
		{
			$this->childs[$tag]->shutdown();
			unset($this->childs[$tag]);
		}
		$this->childs[$tag] = $obj;
		return true;
	}
	
	/**
	 * Return plugin specified property values
	 *	In argument:		OutValues:
	 *		$p = null			array("PropertyName1", ..., "PropertyNameN");
	 *		$p = string			mixed property value
	 *
	 * @param mixed $p
	 * @return mixed
	 */
	function getProperty($p = null)
	{
		return array();
	}
	
	function getURL()
	{
		$p = array();
		$obj = $this;
		while(null != $obj)
		{
			$p[] = $obj->getPluginTag();
			$obj = $obj->parent;
		}
		return "path=".@join(",", @array_reverse($p));
	}


	/*
	*	Install plugin to the system
	*
	*/
	function install()
	{
		return true;
	}
	
	/*
	*	Upgrade plugin from the previous versions
	*
	*/
	function upgrade()
	{
		return true;
	}
	

	/*
	*	Handle plugin actions
	*
	*/
	function doAction($params = null)
	{
		$result = null;

//		debug($params, "IPlugin:Action | ".get_class($this));
//		debug($this, "IPlugin:Action | ".get_class($this));

		if( null != $params && is_array($this->childs) && isset($this->childs[$params[0]]))
		{
			$id = $params[0];
			unset($params[0]);
			$params = ArrayReIndex($params);
			$result = $this->childs[$id]->doAction($params);
		}
		return $result;
	}


	/**
	 * Render plugin content
	 *
	 * @param array $params
	 * @return string HTML response
	 */
	function Render($params = null)
	{
		$result = null;
//		debug($params, "IPlugin | ".get_class($this));
//		debug($this, "IPlugin | ".get_class($this));

		if( null != $params && is_array($this->childs) && isset($this->childs[$params[0]]))
		{
			$id = $params[0];
			$params = ArrayReIndex($params);
			$result = $this->childs[$id]->Render($params);
		}
		return $result;
	}
};

?>